home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
objtools
/
layer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
7KB
|
375 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* layer -
* View an sgi object interactively.
*
* Paul Haeberli - 1990
*/
#include "stdio.h"
#include "gl.h"
#include "device.h"
#include "sgiobj.h"
/*
* layer support follows
*
*/
float fgetmousex();
float fgetmousey();
float flerp();
sgiobj* obj;
int shownormals;
int showlines;
int showcolors;
int showmeshs;
int menu;
int envmap;
main(argc,argv)
int argc;
char **argv;
{
short val;
float zfactor;
if(argc<2) {
fprintf(stderr, "usage: layer object [environ.rgb]\n");
exit(1);
}
obj = readsgiobj(argv[1]);
if(!obj) {
fprintf(stderr, "layer: can't read %s\n",argv[1]);
exit(1);
}
zfactor = 5.0;
initwindow();
trackztrans(-3.0);
if(argc>=3) {
if(getgdesc(GD_TEXTURE)) {
textureread(argv[2],1);
envmap = 1;
} else {
fprintf(stderr, "layer: no texturing on this machine - oh well\n");
}
}
qmouse();
qdevice(ESCKEY);
qdevice(UPARROWKEY);
qdevice(DOWNARROWKEY);
while(1) {
while(qtest()) {
switch(qread(&val)) {
case ESCKEY:
exit(0);
break;
case LEFTMOUSE:
if(val) {
trackclick();
while(getbutton(LEFTMOUSE)) {
trackpoll();
drawit(obj);
}
}
break;
case MIDDLEMOUSE:
if(val) {
trackclick();
while(getbutton(MIDDLEMOUSE)) {
trackpoll();
drawit(obj);
}
}
break;
case MENUBUTTON:
if(val) {
switch(dopup(menu)) {
case 1:
shownormals = 1-shownormals;
break;
case 2:
showlines = 1-showlines;
break;
case 3:
showcolors = 1-showcolors;
break;
case 4:
savewindow("save.rgb");
printf("saved image to save.rgb\n");
break;
case 6:
showmeshs = 1-showmeshs;
break;
}
}
break;
case UPARROWKEY:
if(val) {
zfactor *= 1.41;
}
break;
case DOWNARROWKEY:
if(val) {
zfactor /= 1.41;
}
break;
}
}
drawit(obj);
}
}
initwindow()
{
keepaspect(5,4);
winopen("layer");
if(obj->objtype == OBJ_TRIMESH)
menu = defpup("layer %t|toggle normals|toggle lines|toggle color|save image|save lenticular|toggle showmeshs");
else
menu = defpup("layer %t|toggle normals|toggle lines|toggle color|save image|save lenticular");
matrixinit();
mygfxinit();
backface(0);
renderfperspective(25.0,5.0/4.0,0.3,20.0);
shadeinit();
}
clearback()
{
shadeoff();
cpack(0x000000);
clear();
}
float circpos[4] = { 0.5, 0.5, 0.020, 0.030 };
float rectpos[4] = { 0.3, 0.2,-0.015,-0.025 };
zsetrect(val)
int val;
{
long xsize, ysize;
int x1, x2, y1, y2;
getsize(&xsize,&ysize);
ortho(-0.5,xsize-0.5,-0.5,ysize-0.5,-1.0,1.0);
wmpack(0x00000000);
zfunction(ZF_ALWAYS);
/* outer rectangle */
x1 = 0;
x2 = xsize-0;
y1 = 0;
y2 = ysize-0;
setz(val==0);
rectfi(x1,y1,x2,y2);
/* circle with wire frame */
setz(val==1);
x1 = circpos[0]*xsize;
y1 = circpos[1]*ysize;
circf(x1,y1,xsize*0.12);
circ(x1,y1,xsize*0.12);
/* rectangle with normals */
setz(val==2);
x1 = (rectpos[0]-0.2)*xsize;
x2 = (rectpos[0]+0.2)*xsize;
y1 = (rectpos[1]-0.2)*ysize;
y2 = (rectpos[1]+0.2)*ysize;
rectfi(x1,y1,x2,y2);
recti(x1,y1,x2,y2);
/* draw outlines */
wmpack(0xffffffff);
cpack(0xff0000ff);
zfunction(ZF_LEQUAL);
fsetdepth(0.002,0.003);
if(val == 1) {
x1 = circpos[0]*xsize;
y1 = circpos[1]*ysize;
circ(x1,y1,xsize*0.12);
}
if(val == 2) {
x1 = (rectpos[0]-0.2)*xsize;
x2 = (rectpos[0]+0.2)*xsize;
y1 = (rectpos[1]-0.2)*ysize;
y2 = (rectpos[1]+0.2)*ysize;
recti(x1,y1,x2,y2);
}
fsetdepth(0.000,1.000);
zfunction(ZF_LEQUAL);
}
setz(val)
int val;
{
if(val)
fsetdepth(0.999,1.000);
else
fsetdepth(0.000,0.001);
}
drawit(obj)
sgiobj *obj;
{
float m[4][4];
gettracktransform(m);
reshapeviewport();
clearback();
/* draw it normal */
showlines = 0;
shownormals = 0;
zsetrect(0);
renderfperspective(25.0,5.0/4.0,0.3,20.0);
pushmatrix();
multmatrix(m);
drawtheobj(obj);
popmatrix();
/* draw it as lines */
showlines = 1;
shownormals = 0;
zsetrect(2);
renderfperspective(25.0,5.0/4.0,0.3,20.0);
pushmatrix();
multmatrix(m);
drawtheobj(obj);
popmatrix();
#ifdef NOTDEF
/* draw it as normal with normals */
showlines = 0;
shownormals = 1;
zsetrect(1);
renderfperspective(25.0,5.0/4.0,0.3,20.0);
pushmatrix();
multmatrix(m);
drawtheobj(obj);
popmatrix();
#endif
/* draw it zoomed up in size */
showlines = 0;
shownormals = 1;
zsetrect(1);
renderfperspective(25.0,5.0/4.0,0.3,20.0);
zoomwindow(2.0,circpos[0],circpos[1]);
pushmatrix();
multmatrix(m);
drawtheobj(obj);
popmatrix();
swapbuffers();
updatepos(circpos);
circpos[0] = fgetmousex();
circpos[1] = fgetmousey();
updatepos(rectpos);
}
zoomwindow(zfactor,xpos,ypos)
float zfactor;
float xpos, ypos;
{
float l, r, b, t, near, far;
float tl, tr, tb, tt;
float delx, dely, cenx, ceny;
float shiftx, shifty;
getrenderwindow(&l,&r,&b,&t,&near,&far);
cenx = flerp(l,r,xpos);
tl = cenx+((l-cenx)/zfactor);
tr = cenx+((r-cenx)/zfactor);
ceny = flerp(b,t,ypos);
tb = ceny+((b-ceny)/zfactor);
tt = ceny+((t-ceny)/zfactor);
renderwindow(tl,tr,tb,tt,near,far);
}
updatepos(pos)
float pos[4];
{
pos[0] = pos[0]+pos[2];
if(pos[0]>1.0 || pos[0]<0.0)
pos[2] = -pos[2];
pos[1] = pos[1]+pos[3];
if(pos[1]>1.0 || pos[1]<0.0)
pos[3] = -pos[3];
}
drawtheobj(obj)
sgiobj *obj;
{
srand(3);
if(showlines) {
cpack(0x40ffffff);
drawsgiobj(obj,DRAW_LINES);
} else {
if(envmap) {
cpack(0xffffff);
texgen(TX_S, TG_SPHEREMAP, 0);
texgen(TX_T, TG_SPHEREMAP, 0);
texgen(TX_S, TG_ON, NULL);
texgen(TX_T, TG_ON, NULL);
drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS);
texgen(TX_S, TG_OFF, NULL);
texgen(TX_T, TG_OFF, NULL);
} else {
shadeon();
setdiffuse(0.0,0.6,0.0);
setspecular(0.9,0.9,0.9);
lmcolor(LMC_DIFFUSE);
if(showmeshs)
drawsgiobjmeshs(obj);
else if(showcolors)
drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS|DRAW_COLORS);
else
drawsgiobj(obj,DRAW_POINTS|DRAW_NORMALS);
lmcolor(LMC_COLOR);
shadeoff();
}
}
if(shownormals) {
cpack(0x0000ff);
drawsgiobjnorms(obj);
}
}
mygfxinit()
{
zbuffer(1);
subpixel(1);
RGBmode();
doublebuffer();
gconfig();
cpack(0x808080);
clear();
swapbuffers();
fsetdepth(0.0,1.0);
}